/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.web.util;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class WebUtil {

  public static String getRootPath() {
    String ctx = ResourceFunctions.getCtx();
    if (!ctx.startsWith("http")) {
      HttpServletRequest request =
          ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
      String schema = HsrUtil.getSchema(request);
      String host = HsrUtil.getServerName(request);
      int port = HsrUtil.getServerPort(request);
      String portString =
          (("http".equals(schema) && port == 80) || ("https".equals(schema) && port == 443)) ? ""
              : ":" + port;
      ctx = schema + "://" + host + portString + ctx;
    }
    return ctx;
  }
}
